<template>
	<view class="bg-white p-2">
		<uni-forms label-width="200" :model="form" ref="uForm" label-position="top">
			<div class="flex flex-column">
				<uni-forms-item required :border-bottom="false" name="with_draw_money" label="提现金额(元)"><input
						v-model="form.with_draw_money" placeholder="请输入内容" /></uni-forms-item>
				<uni-forms-item required :border-bottom="false" name="goods_classify_id" label="账户类型">
					<view class="flex align-center border px-2 py-1 bgf7f7f7 rounded" @tap="pickershow = true">
						<text class="flex-1 fs-28">{{form.submit_type?form.submit_typeText:'选择账户类型'}}</text>
						<uni-icons class="ft999999" type="down"></uni-icons>
					</view>
				</uni-forms-item>
				<uni-forms-item required :border-bottom="false" name="with_draw_account" label="到账账户"><input
						v-model="form.with_draw_account" type="number" placeholder="请输入内容" /></uni-forms-item>
				<uni-forms-item required :border-bottom="false" name="with_draw_name" label="账户姓名"><input
						v-model="form.with_draw_name" placeholder="请输入内容" /></uni-forms-item>
				<uni-forms-item v-if="form.submit_type == 2" required :border-bottom="false" name="with_draw_bank"
					label="银行名称"><input v-model="form.with_draw_bank" placeholder="请输入内容" /></uni-forms-item>
			</div>
		</uni-forms>

		<view style="height: 50px;"></view>
		<view class="position-fixed bottom-0 left-0 right-0" style="z-index: 999;">
			<div class="rounded-circle text-center py-2 bge87722cc text-white fs-32 mx-3" @click="submitFn">提交
			</div>
			<view style="height: 40px;"></view>
		</view>

		<u-picker z-index="99999" mode="selector" range-key="lable" v-model="pickershow" :default-selector='selectedIndices'
			:range="rangeData" @confirm="handleChange"></u-picker>
	</view>
</template>

<script>
	import {
		withdrawSubmit
	} from '@/api/store.js'
	export default {
		data() {
			return {
				form: {
					with_draw_money: '',
					submit_type: 2,
					submit_typeText: '银行卡',
					with_draw_account: '',
					with_draw_name: '',
					with_draw_bank: ''
				},
				pickershow: false,
				selectedIndices: [0],
				rangeData: [{
					lable: '银行卡',
					value: 2
				}, {
					lable: '支付宝',
					value: 1
				}]
			}
		},
		methods: {
			submitFn() {
				const data = {
					with_draw_money: this.form.with_draw_money,
					submit_type: this.form.submit_type,
					with_draw_account: this.form.with_draw_account,
					with_draw_name: this.form.with_draw_name,
				}
				if (this.form.submit_type == 2) {
					data.with_draw_bank = this.form.with_draw_bank
				}
				if (Object.keys(data).some(key => !data[key])) {
					uni.showToast({
						title: '请完善提现申请资料',
						icon: 'none'
					})
					return;
				}
				withdrawSubmit(data).then(res => {
					if (res.code == 1) {
						setTimeout(() => {
							uni.redirectTo({
								url: '/pages/store/withdrawalOrder'
							})
						}, 1500)
					}
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				})
			},
			handleChange(e) {
				console.log(e)
				this.selectedIndices = e
				this.form.submit_type = this.rangeData[e[0]]['value']
				this.form.submit_typeText = this.rangeData[e[0]]['lable']
			}
		}
	}
</script>

<style>

</style>